import {Middleware} from "oh-router";
import {getToken} from "../../uitls/token.js";
import {router} from "../index.jsx";
export class LoginCheckMiddleware extends Middleware {
   async handler(ctx, next) {
       // 判断用户有没有登录
       const token = getToken()
       if (ctx.to.pathname === '/login') {
           if (token){
               router.navigate('/')
           }
           return next()
       }
       if (token) {
           await next()
       } else {
           router.navigate('/login')
       }
   }
}
